<script type="text/javascript">
$(document).ready(function(){
	$("a.update").click(function(){
		
		var quantity = $(this).prev().attr("value");
		alert(quantity);
		if(quantity > 0){
			$.ajax({
				url: "<?php echo $this->url(array("action" => "update"), "cart");?>",
				type: "GET",
				data: "pid="+$(this).attr("href")+ "&quantity="+quantity,
				dataType: "html",
				success: function(data){
					location.reload();
				}
			});
		}else{
			alert("Bạn cần nhập đúng định dạng số và lớn hơn 0!");
		}
		return false;
	});
	$("a.delete").click(function(){
		if(confirm("Bạn thực sự muốn loại sản phẩm này khỏi giỏ hàng?")){
			$.ajax({
				url: "<?php echo $this->url(array("action" => "delete"), "cart");?>",
				type: "GET",
				data: "pid="+$(this).attr("href"),
				dataType: "html",
				success: function(data){
					location.reload();
				}
			});
		}
		return false;
	});
	$("#frmSearch").submit(function(){
		var keyword = $("#keyword").attr("value");
		if( keyword == '' || keyword == "Tìm sản phẩm..."){
			alert("Bạn cần nhập từ khóa tìm kiếm!");
			return false;
		}
	});
});
</script>
<div id="main_content">
        	<div id="top">
            	<div id="sub_banner">
            		<?php Helper_HtmlRender::renderImageOrFlash($this->banners[1]->image, 723, 267, 'Thiết bị văn phòng Cường Phú')?>
            	</div>
                <div id="contact_banner">
                	<?php Helper_HtmlRender::renderImageOrFlash($this->banners[2]->image, 723, 76, 'Thiết bị văn phòng Cường Phú')?>
                </div>
            </div><!-- end top main_content block-->
            
            <div id="cart">            
                <div id="guide">
                	<div id="top_guide"></div>
					<div id="bottom_guide">
	                    <b style="text-decoration:underline">Hướng dẫn: </b>Để xóa sản phẩm khỏi giỏ hàng, click <b>Bỏ mua /</b> điền số lượng vào														 ô rồi click <b>Cập nhật</b> 
	                </div>  
                </div>

                
                <table id="cart_table" border="1" bordercolor="#cccccc" >
                	<thead>
                     <tr id="thead">
                        <th width="20%">Số lượng</th>
                        <th width="40%">Sản phẩm</th>
                        <th width="20%">Giá bán</th>
                        <th width="20%">Tổng tiền</th>
                     </tr>
                     </thead>
                     <tbody>
					<?php
					if(!isset($this->cart) && count($this->cart) == 0){
					?>
					<tr>
						<td colspan="4" class = "error">
						Bạn chưa có sản phẩm nào trong giỏ hàng
						</td>
					</tr>
					<?php
					 }else{
					foreach ($this->cart as $product_id => $product)
					{
					?>
					<tr class="trow">
                        <td class="col1">
                        	<input type="text" name="quantity" value="<?php echo $product["quantity"];?>" />
                        	<a class="update" href="<?php echo $product_id;?>">Cập nhật</a> - <a class="delete" href="<?php echo $product_id;?>">Bỏ mua</a>    
                        </td>
                        <td class="col2"><?php echo $product["name"];?></td>
                        <td class="col3"><?php echo number_format($product["price"])?> VND</td>

                        <td class="col4"><?php echo number_format($product["quantity"] * $product["price"])?> VND</td>
                     </tr>
					<?php 	
					 }
					 }
					?>
                     
                    <tr >
                        <td id="total_price_cart_text" colspan="3">Tổng giá trị hóa đơn hàng cần thanh toán: </td>
                        <td id="total_price_cart_value"><?php echo number_format($this->totalPrice);?> VND</td>

                    </tr>
                    </tbody>
                </table>
            </div>
            
            <div id="navigation_button">
            	<a class="cart_button" id="continue_buy" href="<?php echo $this->url(array(), "default");?>">Mua tiếp</a>
                <a target="_blank" class="cart_button" id="print_button" href="<?php echo $this->url(array(""), "print");?>">In báo giá</a>
                <a class="cart_button" id="send_cart" href="<?php echo $this->url(array(), "sendbill");?>">Gửi đơn hàng</a>

            </div>
        </div><!-- end main_content block -->
        <div id="right">
        	<div id="search_box">
        		<form id="frmSearch" action="<?php echo $this->url(array(), "search");?>" method="get">
        			<input type="text" onclick="value='';"  id="keyword" name="keyword" value="Tìm sản phẩm..."/>
                	<input type="submit" id="submit_button" value="Tìm kiếm" />
        		</form>
            	
            </div><!-- end search_block-->
            <div id="cart_box">
            	<div id="title_cart"><a href="<?php echo $this->url(array(),"cart");?>">Giỏ hàng của bạn</a></div>
                <div class="cart_info">
                	<span class="left_info">Số sản phẩm:&nbsp; </span>
                    <span class="right_info"><?php echo $this->totalCartProduct;?></span>
                </div>
                <div class="cart_info">
                	<span class="left_info">Tổng tiền:&nbsp;</span>
                    <span class="right_info"><?php echo number_format($this->totalCartPrice);?> VND</span>
                </div>
            </div> <!-- end cart_block -->
            <?php
            //lấy dữ liệu để điền vào 2 box hỗ trợ trực tuyến
            $arrSalers = array();
            $arrTechnicians = array(); 
            foreach ($this->supporters as $supporter){
            	if($supporter->type == 0){
            		$arrSalers[] = $supporter;
            	}else{
            		$arrTechnicians[] = $supporter;
            	}
            }
            ?>
            <div class="right_box">
            	<div class="title_box">
                	<div class="text_title_box">Bán hàng trực tuyến</div>
                    <div class="phone_title_box">(04) 35 68 36 99</div>
                </div>
                <?php $count_business =count($arrSalers);
               	if($count_business>0){
               	for( $i=0;$i<$count_business;$i++){?>
               	 <div class="supporter">
                	<div class="info_supporter">
                    	<div class="name_supporter">
                        	<a href="ymsgr:SendIM?<?php echo $arrSalers[$i]->yahoo_account;?>"  title="Contact to supporter!">
         						<?php echo $arrSalers[$i]->name;?>
                            </a>
                            </div>
                       	<div class="phone_supporter"><?php echo $arrSalers[$i]->phone;?></div>
                        <div class="email_supporter"><?php echo $arrSalers[$i]->email;?></div>
                        
                    </div>
                    <div class="online_icon">
                        <a href="ymsgr:SendIM?<?php echo $arrSalers[$i]->yahoo_account;?>"  title="Contact to supporter!">
                            <img  src="http://opi.yahoo.com/online?u=<?php echo $arrSalers[$i]->yahoo_account;?>&m=g&t=1" border="0"/>
                        </a>
                    </div>
                    <?php if($i+2 <= $count_business){?><div class="line"></div><?php } ?>
                </div>
               <?php }
               	 } ?>
                
               
            </div><!-- end right_box-->           
            <div class="right_box">
            	<div class="title_box">
                	<div class="text_title_box">Hỗ trợ kỹ thuật</div>
                    <div class="phone_title_box">(04) 66 84 87 86</div>
                </div>
                <?php $count_technical =count($arrTechnicians);
               	if($count_technical>0){
               	for( $i=0;$i<$count_technical;$i++){?>
               	 <div class="supporter">
                	<div class="info_supporter">
                    	<div class="name_supporter">
                        	<a href="ymsgr:SendIM?<?php echo $arrTechnicians[$i]->yahoo_account;?>"  title="Contact to supporter!">
         						<?php echo $arrTechnicians[$i]->name;?>
                            </a>
                            </div>
                        <div class="phone_supporter"><?php echo $arrTechnicians[$i]->phone;?></div>
                        <div class="email_supporter"><?php echo $arrTechnicians[$i]->email;?></div>
                        
                    </div>
                    <a href="ymsgr:SendIM?<?php echo $arrTechnicians[$i]->yahoo_account;?>"  title="Contact to supporter!">
                            <img  alt="" src="http://opi.yahoo.com/online?u=<?php echo $arrTechnicians[$i]->yahoo_account;?>&m=g&t=1" border="0"/>
                        </a>
                    <?php if($i+2 <= $count_technical){?><div class="line"></div><?php } ?>
                </div>
               <?php }
               	 } ?>
            </div><!-- end right_box-->
            <?php
            echo $this->partial("include/tags.phtml", array("tags" => $this->tags));
            ?>
        </div><!-- end right block -->
        <div id="clear"></div>